package com.zoffy.oj_backend.exception;

import com.zoffy.oj_backend.common.BaseResponse;
import com.zoffy.oj_backend.common.ErrorCode;
import com.zoffy.oj_backend.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> businessExceptionHandler(BusinessException businessException){
        return ResultUtils.error(businessException.getCode(), businessException.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public BaseResponse<?> exceptionHandler(Exception exception){
        log.error("Exception: "+exception);
        exception.printStackTrace();
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR);
    }
}
